package com.ruoyi.project.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.product.domain.InsProjectReagentMonthDetail;
import com.ruoyi.project.product.service.IInsProjectReagentMonthDetailService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 产品效期月代码详细Controller
 *
 * @author taney
 * @date 2020-12-15
 */
@AllArgsConstructor
@RestController
@RequestMapping("/product/projectReagentMonthDetail" )
public class InsProjectReagentMonthDetailController extends BaseController {

    private final IInsProjectReagentMonthDetailService iInsProjectReagentMonthDetailService;

    /**
     * 查询产品效期月代码详细列表
     */
    @PreAuthorize("@ss.hasPermi('product:projectReagentMonthDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(InsProjectReagentMonthDetail insProjectReagentMonthDetail)
    {
        startPage();
        LambdaQueryWrapper<InsProjectReagentMonthDetail> lqw = new LambdaQueryWrapper<InsProjectReagentMonthDetail>();
        if (insProjectReagentMonthDetail.getMonth() != null){
            lqw.eq(InsProjectReagentMonthDetail::getMonth ,insProjectReagentMonthDetail.getMonth());
        }
        if (StringUtils.isNotBlank(insProjectReagentMonthDetail.getCodeNo())){
            lqw.eq(InsProjectReagentMonthDetail::getCodeNo ,insProjectReagentMonthDetail.getCodeNo());
        }
        List<InsProjectReagentMonthDetail> list = iInsProjectReagentMonthDetailService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出产品效期月代码详细列表
     */
    @PreAuthorize("@ss.hasPermi('product:projectReagentMonthDetail:export')" )
    @Log(title = "产品效期月代码详细" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(InsProjectReagentMonthDetail insProjectReagentMonthDetail) {
        LambdaQueryWrapper<InsProjectReagentMonthDetail> lqw = new LambdaQueryWrapper<InsProjectReagentMonthDetail>(insProjectReagentMonthDetail);
        List<InsProjectReagentMonthDetail> list = iInsProjectReagentMonthDetailService.list(lqw);
        ExcelUtil<InsProjectReagentMonthDetail> util = new ExcelUtil<InsProjectReagentMonthDetail>(InsProjectReagentMonthDetail. class);
        return util.exportExcel(list, "projectReagentMonthDetail" );
    }

    /**
     * 获取产品效期月代码详细详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:projectReagentMonthDetail:query')" )
    @GetMapping(value = "/{tempId}" )
    public AjaxResult getInfo(@PathVariable("tempId" ) Integer tempId) {
        return AjaxResult.success(iInsProjectReagentMonthDetailService.getById(tempId));
    }

    /**
     * 新增产品效期月代码详细
     */
    @PreAuthorize("@ss.hasPermi('product:projectReagentMonthDetail:add')" )
    @Log(title = "产品效期月代码详细" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InsProjectReagentMonthDetail insProjectReagentMonthDetail) {
        return toAjax(iInsProjectReagentMonthDetailService.save(insProjectReagentMonthDetail) ? 1 : 0);
    }

    /**
     * 修改产品效期月代码详细
     */
    @PreAuthorize("@ss.hasPermi('product:projectReagentMonthDetail:edit')" )
    @Log(title = "产品效期月代码详细" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InsProjectReagentMonthDetail insProjectReagentMonthDetail) {
        return toAjax(iInsProjectReagentMonthDetailService.updateById(insProjectReagentMonthDetail) ? 1 : 0);
    }

    /**
     * 删除产品效期月代码详细
     */
    @PreAuthorize("@ss.hasPermi('product:projectReagentMonthDetail:remove')" )
    @Log(title = "产品效期月代码详细" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{tempIds}" )
    public AjaxResult remove(@PathVariable Integer[] tempIds) {
        return toAjax(iInsProjectReagentMonthDetailService.removeByIds(Arrays.asList(tempIds)) ? 1 : 0);
    }
}
